﻿using GenUI.WPF.GenControls;
using System;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;

namespace Demo
{
    /// <summary>
    /// MainWindow.xaml 的交互逻辑 
    /// </summary>
    public partial class MainWindow : Window
    {
        public PropEdit PropGM { get; set; } = new PropEdit();
        public MainWindow()
        {
            InitializeComponent();
            log.Add("asclaknvoov", LogLevel.Debug, true);
            log.Add("asclaknvoov", LogLevel.Error, true);
            log.Add("asclaknvoovasclaknvooasclaknvoovasclaoovasvasclaknvoov", LogLevel.Important, true);
            log.Add("asclaknvoov", LogLevel.Tips, true);
            log.Add(this.Dispatcher.Thread.Name, LogLevel.Debug, true);
        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            Task.Run(() =>
            {
                while (true)
                {
                    log.Add("JD032333333333", LogLevel.Debug, true);
                    log.Add("JD032323333333", LogLevel.Error, true);
                    log.Add("JD032333433333", LogLevel.Important, true);
                    log.Add("JD032543333333", LogLevel.Tips, true);
                    log.Add(Thread.CurrentThread.Name, LogLevel.Debug, true);
                    Thread.Sleep(1000);
                }
            });
        }

        private void Button_Click_1(object sender, RoutedEventArgs e)
        {
            canvas.AddLine("line1", System.Windows.Media.Brushes.Gray);
            canvas.AddLine("line2", System.Windows.Media.Brushes.Green);
            canvas.AddLine("line3", System.Windows.Media.Brushes.Black);
            canvas.AddLine("line4", System.Windows.Media.Brushes.Purple);
            canvas.AddLine("line5", System.Windows.Media.Brushes.AntiqueWhite);
            canvas.AddLine("line6", System.Windows.Media.Brushes.Azure);
            canvas.AddLine("line7", System.Windows.Media.Brushes.Black);
        }

        private void Button_Click_2(object sender, RoutedEventArgs e)
        {
            Random random = new Random();
            Task.Factory.StartNew(() =>
            {
                while (true)
                {
                    canvas.Add("line1", random.Next(200, 400));
                    canvas.Add("line2", random.Next(200, 400));
                    canvas.Add("line3", random.Next(200, 400));
                    canvas.Add("line4", random.Next(200, 400));
                    canvas.Add("line5", random.Next(200, 400));
                    canvas.Add("line6", random.Next(200, 400));
                    canvas.Add("line7", random.Next(5, 20));
                    Thread.Sleep(1000);
                }
            });
        }

        private void Button_Click_3(object sender, RoutedEventArgs e)
        {
            Random random = new Random();
            cpro.Value = random.NextDouble() * 100;
        }

        private void Button_Click_4(object sender, RoutedEventArgs e)
        {

        }

        private void Button_Click_5(object sender, RoutedEventArgs e)
        {

        }

        private void Button_Click_PropGrid(object sender, RoutedEventArgs e)
        {

        }

        private void Button_Click_6(object sender, RoutedEventArgs e)
        {

        }

        private void Button_Click_7(object sender, RoutedEventArgs e)
        {

        }
        protected bool m_IsDraging = false;
        protected Point m_DragStartPoint;
        private void ListView_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            m_DragStartPoint = e.GetPosition(null);
        }

        private void ListView_PreviewMouseMove(object sender, MouseEventArgs e)
        {
            var lv = sender as ListView;

            if (lv.SelectedItem == null) return;

            if (e.LeftButton == MouseButtonState.Pressed && !m_IsDraging)
            {
                Point position = e.GetPosition(null);

                if (e.LeftButton == MouseButtonState.Pressed && !m_IsDraging)
                {
                    _ = e.GetPosition(null);

                    //if (Math.Abs(position.X - m_DragStartPoint.X) > SystemParameters.MinimumHorizontalDragDistance ||
                    //   Math.Abs(position.Y - m_DragStartPoint.Y) > SystemParameters.MinimumVerticalDragDistance)
                    //{
                    m_IsDraging = true;
                    DataObject data = new DataObject(typeof(Label), lv.SelectedItem);
                    DragDropEffects de = DragDrop.DoDragDrop(lv, data, DragDropEffects.Copy);
                    //SelectType = lv.SelectedItem;
                    m_IsDraging = false;
                    // }
                }
            }
        }


        private void outsidewrapper_PreviewMouseDown(object sender, MouseButtonEventArgs e)
        {

        }

        private void Canvas_KeyDown(object sender, KeyEventArgs e)
        {
            MessageBox.Show(e.Key.ToString());
        }
    }
    [PropGridMap(name:"属性编辑器")]
    public class PropEdit
    {
        [PropGridMap(name: "整数")]
        public int textInt { get; set; } = 0;
        public DateTime 时间 { get; set; } = DateTime.Now;
        public TestEnum 枚举 { get; set; } = TestEnum.None;
        public bool 布尔 { get; set; } = false;
        public enum TestEnum
        {
            None,
            One,
        }
    }
}
